package leetcode.code0150;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int evalRPN(String[] tokens) {
		int len = tokens.length;
		int[] stack = new int[len];
		int p = -1;
		for (String token : tokens) {
			if (token.equals("+")) {
				int num1 = stack[p--];
				int num2 = stack[p];
				stack[p] = num2 + num1;
			} else if (token.equals("-")) {
				int num1 = stack[p--];
				int num2 = stack[p];
				stack[p] = num2 - num1;
			} else if (token.equals("*")) {
				int num1 = stack[p--];
				int num2 = stack[p];
				stack[p] = num2 * num1;
			} else if (token.equals("/")) {
				int num1 = stack[p--];
				int num2 = stack[p];
				stack[p] = num2 / num1;
			} else {
				stack[++p] = Integer.valueOf(token);
			}
		}
		return stack[p];
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
